using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Objects;
using System.Text;
using Acme.Northwind.EFDAL;
using nHydrate.EFCore.DataAccess;
using nHydrate.EFCore.EventArgs;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.Linq;

namespace Acme.Northwind.EFDAL.Entity
{
	/// <summary>
	/// The collection to hold 'Employee' entities
	/// </summary>
	[System.CodeDom.Compiler.GeneratedCode("nHydrateModelGenerator", "5.0.1.100")]
	[EdmEntityTypeAttribute(NamespaceName="Acme.Northwind.EFDAL.Entity", Name="Employee")]
	[Serializable()]
	[DataContractAttribute(IsReference = true)]
	[nHydrate.EFCore.Attributes.FieldNameConstantsAttribute(typeof(Acme.Northwind.EFDAL.Entity.Employee.FieldNameConstants))]
	[System.ComponentModel.DataAnnotations.MetadataType(typeof(Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.EmployeeMetadata))]
	[nHydrate.EFCore.Attributes.EntityMetadata("Employee", false, true, true, true, "", true, false, false, "dbo")]
	public partial class Employee : nHydrate.EFCore.DataAccess.NHEntityObject, nHydrate.EFCore.DataAccess.IBusinessObject, Acme.Northwind.EFDAL.IEntityWithContext, Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee, System.ICloneable, nHydrate.EFCore.DataAccess.IAuditable, System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee>
	{
		#region FieldImageConstants Enumeration

		/// <summary>
		/// An enumeration of this object's image type fields
		/// </summary>
		public enum FieldImageConstants
		{
			/// <summary>
			/// Field mapping for the image parameter 'Photo' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the image parameter 'Photo' property")]
			Photo,
		}

		#endregion

		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'Employee' table.
		/// </summary>
		public enum FieldNameConstants
		{
			/// <summary>
			/// Field mapping for the 'Address' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Address' property")]
			Address,
			/// <summary>
			/// Field mapping for the 'BirthDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'BirthDate' property")]
			BirthDate,
			/// <summary>
			/// Field mapping for the 'City' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'City' property")]
			City,
			/// <summary>
			/// Field mapping for the 'Country' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Country' property")]
			Country,
			/// <summary>
			/// Field mapping for the 'EmployeeID' property
			/// </summary>
			[nHydrate.EFCore.Attributes.PrimaryKeyAttribute()]
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'EmployeeID' property")]
			EmployeeID,
			/// <summary>
			/// Field mapping for the 'Extension' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Extension' property")]
			Extension,
			/// <summary>
			/// Field mapping for the 'FirstName' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'FirstName' property")]
			FirstName,
			/// <summary>
			/// Field mapping for the 'HireDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'HireDate' property")]
			HireDate,
			/// <summary>
			/// Field mapping for the 'HomePhone' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'HomePhone' property")]
			HomePhone,
			/// <summary>
			/// Field mapping for the 'LastName' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'LastName' property")]
			LastName,
			/// <summary>
			/// Field mapping for the 'Notes' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Notes' property")]
			Notes,
			/// <summary>
			/// Field mapping for the 'Photo' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Photo' property")]
			Photo,
			/// <summary>
			/// Field mapping for the 'PhotoPath' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'PhotoPath' property")]
			PhotoPath,
			/// <summary>
			/// Field mapping for the 'PostalCode' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'PostalCode' property")]
			PostalCode,
			/// <summary>
			/// Field mapping for the 'Region' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Region' property")]
			Region,
			/// <summary>
			/// Field mapping for the 'ReportsTo' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ReportsTo' property")]
			ReportsTo,
			/// <summary>
			/// Field mapping for the 'Title' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Title' property")]
			Title,
			/// <summary>
			/// Field mapping for the 'TitleOfCourtesy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'TitleOfCourtesy' property")]
			TitleOfCourtesy,
			/// <summary>
			/// Field mapping for the 'CreatedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedBy' property")]
			CreatedBy,
			/// <summary>
			/// Field mapping for the 'CreatedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedDate' property")]
			CreatedDate,
			/// <summary>
			/// Field mapping for the 'ModifiedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedBy' property")]
			ModifiedBy,
			/// <summary>
			/// Field mapping for the 'ModifiedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedDate' property")]
			ModifiedDate,
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Method called when an instance of this class is created
		/// </summary>
		partial void OnCreated();

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.Employee class
		/// </summary>
		public Employee()
		{
			this.OnCreated();
		}

		#endregion

		#region Properties

		/// <summary>
		/// The property that maps back to the database 'Employees.Address' field
		/// </summary>
		/// <remarks>Field: [Employees].[Address], Field Length: 60, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Address")]
		public virtual string Address
		{
			get { return _address; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Address))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Address", GetMaxLength(FieldNameConstants.Address)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Address");
				//this.OnAddressChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Address");
				_address = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Address");
				//this.OnAddressChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.BirthDate' field
		/// </summary>
		/// <remarks>Field: [Employees].[BirthDate], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("BirthDate")]
		public virtual DateTime? BirthDate
		{
			get { return _birthDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'BirthDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'BirthDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "BirthDate");
				//this.OnBirthDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("BirthDate");
				_birthDate = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("BirthDate");
				//this.OnBirthDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.City' field
		/// </summary>
		/// <remarks>Field: [Employees].[City], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("City")]
		public virtual string City
		{
			get { return _city; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.City))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.City", GetMaxLength(FieldNameConstants.City)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "City");
				//this.OnCityChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("City");
				_city = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("City");
				//this.OnCityChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Country' field
		/// </summary>
		/// <remarks>Field: [Employees].[Country], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Country")]
		public virtual string Country
		{
			get { return _country; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Country))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Country", GetMaxLength(FieldNameConstants.Country)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Country");
				//this.OnCountryChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Country");
				_country = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Country");
				//this.OnCountryChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.EmployeeID' field
		/// </summary>
		/// <remarks>Field: [Employees].[EmployeeID], Not Nullable, Primary Key, Unique, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("EmployeeID")]
		[System.ComponentModel.DataAnnotations.Key()]
		[System.ComponentModel.ReadOnly(true)]
		public virtual int EmployeeID
		{
			get { return _employeeID; }
			set
			{
				ReportPropertyChanging("EmployeeID");
				_employeeID = value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("EmployeeID");
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Extension' field
		/// </summary>
		/// <remarks>Field: [Employees].[Extension], Field Length: 4, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Extension")]
		public virtual string Extension
		{
			get { return _extension; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Extension))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Extension", GetMaxLength(FieldNameConstants.Extension)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Extension");
				//this.OnExtensionChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Extension");
				_extension = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Extension");
				//this.OnExtensionChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.FirstName' field
		/// </summary>
		/// <remarks>Field: [Employees].[FirstName], Field Length: 10, Not Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("FirstName")]
		public virtual string FirstName
		{
			get { return _firstName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.FirstName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.FirstName", GetMaxLength(FieldNameConstants.FirstName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "FirstName");
				//this.OnFirstNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("FirstName");
				_firstName = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("FirstName");
				//this.OnFirstNameChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.HireDate' field
		/// </summary>
		/// <remarks>Field: [Employees].[HireDate], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("HireDate")]
		public virtual DateTime? HireDate
		{
			get { return _hireDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'HireDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'HireDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "HireDate");
				//this.OnHireDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("HireDate");
				_hireDate = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("HireDate");
				//this.OnHireDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.HomePhone' field
		/// </summary>
		/// <remarks>Field: [Employees].[HomePhone], Field Length: 24, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("HomePhone")]
		public virtual string HomePhone
		{
			get { return _homePhone; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.HomePhone))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.HomePhone", GetMaxLength(FieldNameConstants.HomePhone)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "HomePhone");
				//this.OnHomePhoneChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("HomePhone");
				_homePhone = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("HomePhone");
				//this.OnHomePhoneChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.LastName' field
		/// </summary>
		/// <remarks>Field: [Employees].[LastName], Field Length: 20, Not Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("LastName")]
		public virtual string LastName
		{
			get { return _lastName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.LastName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.LastName", GetMaxLength(FieldNameConstants.LastName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "LastName");
				//this.OnLastNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("LastName");
				_lastName = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("LastName");
				//this.OnLastNameChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Notes' field
		/// </summary>
		/// <remarks>Field: [Employees].[Notes], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Notes")]
		public virtual string Notes
		{
			get { return _notes; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Notes))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Notes", GetMaxLength(FieldNameConstants.Notes)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Notes");
				//this.OnNotesChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Notes");
				_notes = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Notes");
				//this.OnNotesChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Photo' field
		/// </summary>
		/// <remarks>Field: [Employees].[Photo], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Photo")]
		public virtual System.Byte[] Photo
		{
			get { return _photo; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<System.Byte[]>(value, "Photo");
				//this.OnPhotoChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Photo");
				_photo = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Photo");
				//this.OnPhotoChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.PhotoPath' field
		/// </summary>
		/// <remarks>Field: [Employees].[PhotoPath], Field Length: 255, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("PhotoPath")]
		public virtual string PhotoPath
		{
			get { return _photoPath; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.PhotoPath))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.PhotoPath", GetMaxLength(FieldNameConstants.PhotoPath)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "PhotoPath");
				//this.OnPhotoPathChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("PhotoPath");
				_photoPath = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("PhotoPath");
				//this.OnPhotoPathChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.PostalCode' field
		/// </summary>
		/// <remarks>Field: [Employees].[PostalCode], Field Length: 10, Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("PostalCode")]
		public virtual string PostalCode
		{
			get { return _postalCode; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.PostalCode))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.PostalCode", GetMaxLength(FieldNameConstants.PostalCode)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "PostalCode");
				//this.OnPostalCodeChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("PostalCode");
				_postalCode = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("PostalCode");
				//this.OnPostalCodeChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Region' field
		/// </summary>
		/// <remarks>Field: [Employees].[Region], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Region")]
		public virtual string Region
		{
			get { return _region; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Region))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Region", GetMaxLength(FieldNameConstants.Region)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Region");
				//this.OnRegionChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Region");
				_region = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Region");
				//this.OnRegionChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.ReportsTo' field
		/// </summary>
		/// <remarks>Field: [Employees].[ReportsTo], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ReportsTo")]
		public virtual int? ReportsTo
		{
			get { return _reportsTo; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<int?>(value, "ReportsTo");
				//this.OnReportsToChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ReportsTo");
				_reportsTo = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ReportsTo");
				//this.OnReportsToChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.Title' field
		/// </summary>
		/// <remarks>Field: [Employees].[Title], Field Length: 30, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Title")]
		public virtual string Title
		{
			get { return _title; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Title))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.Title", GetMaxLength(FieldNameConstants.Title)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Title");
				//this.OnTitleChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Title");
				_title = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Title");
				//this.OnTitleChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Employees.TitleOfCourtesy' field
		/// </summary>
		/// <remarks>Field: [Employees].[TitleOfCourtesy], Field Length: 25, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("TitleOfCourtesy")]
		public virtual string TitleOfCourtesy
		{
			get { return _titleOfCourtesy; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.TitleOfCourtesy))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Employee.TitleOfCourtesy", GetMaxLength(FieldNameConstants.TitleOfCourtesy)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "TitleOfCourtesy");
				//this.OnTitleOfCourtesyChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("TitleOfCourtesy");
				_titleOfCourtesy = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("TitleOfCourtesy");
				//this.OnTitleOfCourtesyChanged(eventArg);
			}
		}

		/// <summary>
		/// The audit field for the 'Created By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string CreatedBy
		{
			get { return _createdby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CreatedBy");
				//OnCreatedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedBy");
				_createdby = eventArg.Value;
				ReportPropertyChanged("CreatedBy");
				//OnCreatedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createdby' property
		/// </summary>
		protected string _createdby;

		/// <summary>
		/// The audit field for the 'Created Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? CreatedDate
		{
			get { return _createddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "CreatedDate");
				//OnCreatedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedDate");
				_createddate = eventArg.Value;
				ReportPropertyChanged("CreatedDate");
				//OnCreatedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createddate' property
		/// </summary>
		protected DateTime? _createddate;

		/// <summary>
		/// The audit field for the 'Modified By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string ModifiedBy
		{
			get { return _modifiedby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ModifiedBy");
				//OnModifiedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedBy");
				_modifiedby = eventArg.Value;
				ReportPropertyChanged("ModifiedBy");
				//OnModifiedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifiedby' property
		/// </summary>
		protected string _modifiedby;

		/// <summary>
		/// The audit field for the 'Modified Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? ModifiedDate
		{
			get { return _modifieddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "ModifiedDate");
				//OnModifiedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedDate");
				_modifieddate = eventArg.Value;
				ReportPropertyChanged("ModifiedDate");
				//OnModifiedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifieddate' property
		/// </summary>
		protected DateTime? _modifieddate;

		/// <summary>
		/// The audit field for the 'Timestamp' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual byte[] Timestamp
		{
			get { return _timestamp; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<byte[]>(value, "Timestamp");
				//OnTimestampChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Timestamp");
				_timestamp = eventArg.Value;
				ReportPropertyChanged("Timestamp");
				//OnTimestampChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'timestamp' property
		/// </summary>
		protected byte[] _timestamp;

		#endregion

		#region Events

		/// <summary>
		/// The internal reference variable for the 'Address' property
		/// </summary>
		protected string _address;

		/// <summary>
		/// The internal reference variable for the 'BirthDate' property
		/// </summary>
		protected DateTime? _birthDate;

		/// <summary>
		/// The internal reference variable for the 'City' property
		/// </summary>
		protected string _city;

		/// <summary>
		/// The internal reference variable for the 'Country' property
		/// </summary>
		protected string _country;

		/// <summary>
		/// The internal reference variable for the 'EmployeeID' property
		/// </summary>
		protected int _employeeID;

		/// <summary>
		/// The internal reference variable for the 'Extension' property
		/// </summary>
		protected string _extension;

		/// <summary>
		/// The internal reference variable for the 'FirstName' property
		/// </summary>
		protected string _firstName;

		/// <summary>
		/// The internal reference variable for the 'HireDate' property
		/// </summary>
		protected DateTime? _hireDate;

		/// <summary>
		/// The internal reference variable for the 'HomePhone' property
		/// </summary>
		protected string _homePhone;

		/// <summary>
		/// The internal reference variable for the 'LastName' property
		/// </summary>
		protected string _lastName;

		/// <summary>
		/// The internal reference variable for the 'Notes' property
		/// </summary>
		protected string _notes;

		/// <summary>
		/// The internal reference variable for the 'Photo' property
		/// </summary>
		protected System.Byte[] _photo;

		/// <summary>
		/// The internal reference variable for the 'PhotoPath' property
		/// </summary>
		protected string _photoPath;

		/// <summary>
		/// The internal reference variable for the 'PostalCode' property
		/// </summary>
		protected string _postalCode;

		/// <summary>
		/// The internal reference variable for the 'Region' property
		/// </summary>
		protected string _region;

		/// <summary>
		/// The internal reference variable for the 'ReportsTo' property
		/// </summary>
		protected int? _reportsTo;

		/// <summary>
		/// The internal reference variable for the 'Title' property
		/// </summary>
		protected string _title;

		/// <summary>
		/// The internal reference variable for the 'TitleOfCourtesy' property
		/// </summary>
		protected string _titleOfCourtesy;

		#endregion

		#region GetMaxLength

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.Address:
					return 60;
				case FieldNameConstants.BirthDate:
					return 0;
				case FieldNameConstants.City:
					return 15;
				case FieldNameConstants.Country:
					return 15;
				case FieldNameConstants.EmployeeID:
					return 0;
				case FieldNameConstants.Extension:
					return 4;
				case FieldNameConstants.FirstName:
					return 10;
				case FieldNameConstants.HireDate:
					return 0;
				case FieldNameConstants.HomePhone:
					return 24;
				case FieldNameConstants.LastName:
					return 20;
				case FieldNameConstants.Notes:
					return int.MaxValue;
				case FieldNameConstants.Photo:
					return int.MaxValue;
				case FieldNameConstants.PhotoPath:
					return 255;
				case FieldNameConstants.PostalCode:
					return 10;
				case FieldNameConstants.Region:
					return 15;
				case FieldNameConstants.ReportsTo:
					return 0;
				case FieldNameConstants.Title:
					return 30;
				case FieldNameConstants.TitleOfCourtesy:
					return 25;
			}
			return 0;
		}

		int nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		#endregion

		#region GetFieldNameConstants

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldNameConstants()
		{
			return typeof(FieldNameConstants);
		}

		#endregion

		#region GetFieldType

		/// <summary>
		/// Gets the system type of a field on this object
		/// </summary>
		public static System.Type GetFieldType(FieldNameConstants field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.Employee.FieldNameConstants'.");

			var array = Enum.GetValues(typeof(FieldNameConstants));
			switch ((FieldNameConstants)field)
			{
				case FieldNameConstants.Address: return typeof(string);
				case FieldNameConstants.BirthDate: return typeof(DateTime?);
				case FieldNameConstants.City: return typeof(string);
				case FieldNameConstants.Country: return typeof(string);
				case FieldNameConstants.EmployeeID: return typeof(int);
				case FieldNameConstants.Extension: return typeof(string);
				case FieldNameConstants.FirstName: return typeof(string);
				case FieldNameConstants.HireDate: return typeof(DateTime?);
				case FieldNameConstants.HomePhone: return typeof(string);
				case FieldNameConstants.LastName: return typeof(string);
				case FieldNameConstants.Notes: return typeof(string);
				case FieldNameConstants.Photo: return typeof(System.Byte[]);
				case FieldNameConstants.PhotoPath: return typeof(string);
				case FieldNameConstants.PostalCode: return typeof(string);
				case FieldNameConstants.Region: return typeof(string);
				case FieldNameConstants.ReportsTo: return typeof(int?);
				case FieldNameConstants.Title: return typeof(string);
				case FieldNameConstants.TitleOfCourtesy: return typeof(string);
			}
			return null;
		}

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldType(Enum field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.Employee.FieldNameConstants'.");

			return GetFieldType((Acme.Northwind.EFDAL.Entity.Employee.FieldNameConstants)field);
		}

		#endregion

		#region Get/Set Value

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field)
		{
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)this).GetValue(field, null);
		}

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field, object defaultValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		void nHydrate.EFCore.DataAccess.IBusinessObject.SetValue(System.Enum field, object newValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			this.SetValue((FieldNameConstants)field, newValue);
		}

		#endregion

		#region PrimaryKey

		/// <summary>
		/// Hold the primary key for this object
		/// </summary>
		protected nHydrate.EFCore.DataAccess.IPrimaryKey _primaryKey = null;
		nHydrate.EFCore.DataAccess.IPrimaryKey nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.PrimaryKey
		{
			get
			{
				if (_primaryKey == null) _primaryKey = new Acme.Northwind.EFDAL.Entity.EmployeePrimaryKey(this.EmployeeID);
				return _primaryKey;
			}
		}

		#endregion

		#region IsParented

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (this.EntityState != System.Data.EntityState.Detached); }
		}

		#endregion

		#region Clone

		/// <summary>
		/// Creates a shallow copy of this object of all simple properties
		/// </summary>
		/// <returns></returns>
		public virtual object Clone()
		{
			var newItem = new Employee();
			newItem._address = this._address;
			newItem._birthDate = this._birthDate;
			newItem._city = this._city;
			newItem._country = this._country;
			newItem._extension = this._extension;
			newItem._firstName = this._firstName;
			newItem._hireDate = this._hireDate;
			newItem._homePhone = this._homePhone;
			newItem._lastName = this._lastName;
			newItem._notes = this._notes;
			newItem._photo = this._photo;
			newItem._photoPath = this._photoPath;
			newItem._postalCode = this._postalCode;
			newItem._region = this._region;
			newItem._reportsTo = this._reportsTo;
			newItem._title = this._title;
			newItem._titleOfCourtesy = this._titleOfCourtesy;
			return newItem;
		}

		#endregion

		#region IsEquivalent

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(nHydrate.EFCore.DataAccess.INHEntityObject item)
		{
			if (item == null) return false;
			if (!(item is Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee)) return false;
			var o = item as Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee;
			return (
				o.Address == this.Address &&
				o.BirthDate == this.BirthDate &&
				o.City == this.City &&
				o.Country == this.Country &&
				o.EmployeeID == this.EmployeeID &&
				o.Extension == this.Extension &&
				o.FirstName == this.FirstName &&
				o.HireDate == this.HireDate &&
				o.HomePhone == this.HomePhone &&
				o.LastName == this.LastName &&
				o.Notes == this.Notes &&
				o.Photo == this.Photo &&
				o.PhotoPath == this.PhotoPath &&
				o.PostalCode == this.PostalCode &&
				o.Region == this.Region &&
				o.ReportsTo == this.ReportsTo &&
				o.Title == this.Title &&
				o.TitleOfCourtesy == this.TitleOfCourtesy
				);
		}

		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if (field == FieldNameConstants.Address)
				return ((this.Address == null) ? defaultValue : this.Address);
			if (field == FieldNameConstants.BirthDate)
				return ((this.BirthDate == null) ? defaultValue : this.BirthDate);
			if (field == FieldNameConstants.City)
				return ((this.City == null) ? defaultValue : this.City);
			if (field == FieldNameConstants.Country)
				return ((this.Country == null) ? defaultValue : this.Country);
			if (field == FieldNameConstants.EmployeeID)
				return this.EmployeeID;
			if (field == FieldNameConstants.Extension)
				return ((this.Extension == null) ? defaultValue : this.Extension);
			if (field == FieldNameConstants.FirstName)
				return this.FirstName;
			if (field == FieldNameConstants.HireDate)
				return ((this.HireDate == null) ? defaultValue : this.HireDate);
			if (field == FieldNameConstants.HomePhone)
				return ((this.HomePhone == null) ? defaultValue : this.HomePhone);
			if (field == FieldNameConstants.LastName)
				return this.LastName;
			if (field == FieldNameConstants.Notes)
				return ((this.Notes == null) ? defaultValue : this.Notes);
			if (field == FieldNameConstants.Photo)
				return ((this.Photo == null) ? defaultValue : this.Photo);
			if (field == FieldNameConstants.PhotoPath)
				return ((this.PhotoPath == null) ? defaultValue : this.PhotoPath);
			if (field == FieldNameConstants.PostalCode)
				return ((this.PostalCode == null) ? defaultValue : this.PostalCode);
			if (field == FieldNameConstants.Region)
				return ((this.Region == null) ? defaultValue : this.Region);
			if (field == FieldNameConstants.ReportsTo)
				return ((this.ReportsTo == null) ? defaultValue : this.ReportsTo);
			if (field == FieldNameConstants.Title)
				return ((this.Title == null) ? defaultValue : this.Title);
			if (field == FieldNameConstants.TitleOfCourtesy)
				return ((this.TitleOfCourtesy == null) ? defaultValue : this.TitleOfCourtesy);
			if (field == FieldNameConstants.CreatedBy)
				return ((this.CreatedBy == null) ? defaultValue : this.CreatedBy);
			if (field == FieldNameConstants.CreatedDate)
				return ((this.CreatedDate == null) ? defaultValue : this.CreatedDate);
			if (field == FieldNameConstants.ModifiedBy)
				return ((this.ModifiedBy == null) ? defaultValue : this.ModifiedBy);
			if (field == FieldNameConstants.ModifiedDate)
				return ((this.ModifiedDate == null) ? defaultValue : this.ModifiedDate);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region SetValue

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		public void SetValue(FieldNameConstants field, object newValue)
		{
			SetValue(field, newValue, false);
		}

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		/// <param name="fixLength">Determines if the length should be truncated if too long. When false, an error will be raised if data is too large to be assigned to the field.</param>
		public void SetValue(FieldNameConstants field, object newValue, bool fixLength)
		{
			if (field == FieldNameConstants.Address)
			{
				this.Address = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.BirthDate)
			{
				this.BirthDate = GlobalValues.SetValueHelperDateTimeNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.City)
			{
				this.City = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.Country)
			{
				this.Country = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.EmployeeID)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.Extension)
			{
				this.Extension = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.FirstName)
			{
				this.FirstName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.HireDate)
			{
				this.HireDate = GlobalValues.SetValueHelperDateTimeNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.HomePhone)
			{
				this.HomePhone = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.LastName)
			{
				this.LastName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.Notes)
			{
				this.Notes = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.Photo)
			{
				if (newValue == null)
				{
					this.Photo = null;
				}
				else
				{
					this.Photo = (System.Byte[])newValue;
				}
			}
			else if (field == FieldNameConstants.PhotoPath)
			{
				this.PhotoPath = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.PostalCode)
			{
				this.PostalCode = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.Region)
			{
				this.Region = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ReportsTo)
			{
				this.ReportsTo = GlobalValues.SetValueHelperIntNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.Title)
			{
				this.Title = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.TitleOfCourtesy)
			{
				this.TitleOfCourtesy = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else
				throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region Navigation Properties

		/// <summary>
		/// The back navigation definition for walking [Employee]->[Employee]
		/// Relationship Links: 
		/// [Employees.EmployeeID = Employees.ReportsTo] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK_ReportTo_Employee_Employee", "ReportToEmployeeList")]
		public virtual EntityCollection<Acme.Northwind.EFDAL.Entity.Employee> ReportToEmployeeList
		{
			get
			{
				//Eager load
				var retval = ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Acme.Northwind.EFDAL.Entity.Employee>("Acme.Northwind.EFDAL.Entity.FK_ReportTo_Employee_Employee", "ReportToEmployeeList");
				if (!retval.IsLoaded  && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval;
			}
		}

		#region IEmployee Interface

		System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee> Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee.ReportToEmployeeList
		{
			get { return (System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee>)(System.Collections.Generic.ICollection<Employee>)this.ReportToEmployeeList; }
		}

		#endregion

		/// <summary>
		/// The back navigation definition for walking [Employee]->[EmployeeTerritorie]
		/// Relationship Links: 
		/// [Employees.EmployeeID = EmployeeTerritories.EmployeeID] (Required)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK__EmployeeTerritorie_Employee", "EmployeeTerritorieList")]
		public virtual EntityCollection<Acme.Northwind.EFDAL.Entity.EmployeeTerritorie> EmployeeTerritorieList
		{
			get
			{
				//Eager load
				var retval = ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Acme.Northwind.EFDAL.Entity.EmployeeTerritorie>("Acme.Northwind.EFDAL.Entity.FK__EmployeeTerritorie_Employee", "EmployeeTerritorieList");
				if (!retval.IsLoaded  && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval;
			}
		}

		#region IEmployee Interface

		System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployeeTerritorie> Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee.EmployeeTerritorieList
		{
			get { return (System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployeeTerritorie>)(System.Collections.Generic.ICollection<EmployeeTerritorie>)this.EmployeeTerritorieList; }
		}

		#endregion

		/// <summary>
		/// The back navigation definition for walking [Employee]->[Order]
		/// Relationship Links: 
		/// [Employees.EmployeeID = Orders.EmployeeID] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK__Order_Employee", "OrderList")]
		public virtual EntityCollection<Acme.Northwind.EFDAL.Entity.Order> OrderList
		{
			get
			{
				//Eager load
				var retval = ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Acme.Northwind.EFDAL.Entity.Order>("Acme.Northwind.EFDAL.Entity.FK__Order_Employee", "OrderList");
				if (!retval.IsLoaded  && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval;
			}
		}

		#region IEmployee Interface

		System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IOrder> Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee.OrderList
		{
			get { return (System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IOrder>)(System.Collections.Generic.ICollection<Order>)this.OrderList; }
		}

		#endregion

		/// <summary>
		/// The navigation definition for walking [Employee]->[Employee]
		/// Relationship Links: 
		/// [Employees.EmployeeID = Employees.ReportsTo] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK_ReportTo_Employee_Employee", "ReportToEmployee")]
		public virtual Employee ReportToEmployee
		{
			get
			{
				var retval = ReportToEmployeeReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK_ReportTo_Employee_Employee", "ReportToEmployee").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Employee->Employee
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Employee> ReportToEmployeeReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK_ReportTo_Employee_Employee", "ReportToEmployee"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK_ReportTo_Employee_Employee", "ReportToEmployee", value);
			}
		}

		#region IEmployee Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee.ReportToEmployee
		{
			get { return this.ReportToEmployee; }
			set { this.ReportToEmployee = (Acme.Northwind.EFDAL.Entity.Employee)value; }
		}

		#endregion

		#endregion

		#region Static SQL Methods

		internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
		{
			alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
			switch (alias.ToLower())
			{
				case "address": return "address";
				case "birthdate": return "birthdate";
				case "city": return "city";
				case "country": return "country";
				case "employeeid": return "employeeid";
				case "extension": return "extension";
				case "firstname": return "firstname";
				case "hiredate": return "hiredate";
				case "homephone": return "homephone";
				case "lastname": return "lastname";
				case "notes": return "notes";
				case "photo": return "photo";
				case "photopath": return "photopath";
				case "postalcode": return "postalcode";
				case "region": return "region";
				case "reportsto": return "reportsto";
				case "title": return "title";
				case "titleofcourtesy": return "titleofcourtesy";
				case "createddate": return "createddate";
				case "createdby": return "createdby";
				case "modifieddate": return "modifieddate";
				case "modifiedby": return "modifiedby";
				case "timestamp": return "timestamp";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldAliasSqlMapping(string alias)
		{
			switch (alias.ToLower())
			{
				case "address": return "Employees";
				case "birthdate": return "Employees";
				case "city": return "Employees";
				case "country": return "Employees";
				case "employeeid": return "Employees";
				case "extension": return "Employees";
				case "firstname": return "Employees";
				case "hiredate": return "Employees";
				case "homephone": return "Employees";
				case "lastname": return "Employees";
				case "notes": return "Employees";
				case "photo": return "Employees";
				case "photopath": return "Employees";
				case "postalcode": return "Employees";
				case "region": return "Employees";
				case "reportsto": return "Employees";
				case "title": return "Employees";
				case "titleofcourtesy": return "Employees";
				case "createdby": return "Employees";
				case "createddate": return "Employees";
				case "modifiedby": return "Employees";
				case "modifieddate": return "Employees";
				case "timestamp": return "Employees";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldNameSqlMapping(string field)
		{
			switch (field.ToLower())
			{
				case "address": return "Employees";
				case "birthdate": return "Employees";
				case "city": return "Employees";
				case "country": return "Employees";
				case "employeeid": return "Employees";
				case "extension": return "Employees";
				case "firstname": return "Employees";
				case "hiredate": return "Employees";
				case "homephone": return "Employees";
				case "lastname": return "Employees";
				case "notes": return "Employees";
				case "photo": return "Employees";
				case "photopath": return "Employees";
				case "postalcode": return "Employees";
				case "region": return "Employees";
				case "reportsto": return "Employees";
				case "title": return "Employees";
				case "titleofcourtesy": return "Employees";
				case "createdby": return "Employees";
				case "createddate": return "Employees";
				case "modifiedby": return "Employees";
				case "modifieddate": return "Employees";
				case "timestamp": return "Employees";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
		{
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[address\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[address]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[birthdate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[birthdate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[city\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[city]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[country\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[country]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[employeeid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[employeeid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[extension\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[extension]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[firstname\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[firstname]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[hiredate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[hiredate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[homephone\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[homephone]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[lastname\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[lastname]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[notes\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[notes]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[photo\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[photo]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[photopath\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[photopath]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[postalcode\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[postalcode]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[region\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[region]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[reportsto\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[reportsto]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[title\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[title]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[titleofcourtesy\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[titleofcourtesy]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createdby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[createdby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[createddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifiedby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[modifiedby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifieddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[modifieddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[timestamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Employees") + "].[timestamp]", RegexOptions.IgnoreCase);
			return sql;
		}

		#endregion

		#region DeleteData

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where)
		{
			return DeleteData(where, new nHydrate.EFCore.DataAccess.QueryOptimizer());
		}

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <param name="optimizer">The optimization object to use for running queries</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, nHydrate.EFCore.DataAccess.QueryOptimizer optimizer)
		{
			if (optimizer == null) throw new Exception("The 'optimizer' parameter cannot be null.");

			var dc = new DataContext(Acme.Northwind.EFDAL.DBHelper.GetConnection());
			var  template = dc.GetTable<Acme.Northwind.EFDAL.EmployeeQuery>();
			var cmd = nHydrate.EFCore.DataAccess.BusinessEntityQuery.GetCommand<Acme.Northwind.EFDAL.EmployeeQuery>(dc, template, where);
			cmd.CommandTimeout = 30;

			var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table);
			string sql = "SELECT [t0].[EmployeeID] INTO #t\r\n";
			sql += parser.GetFromClause(optimizer) + "\r\n";
			sql += parser.GetWhereClause();
			sql += "\r\n";

			var noLock = string.Empty;
			noLock = (optimizer.NoLocking ? "WITH (NOLOCK) " : string.Empty);
			sql += "DELETE [Employees] FROM [dbo].[Employees] " + noLock + "INNER JOIN #t ON [dbo].[Employees].[EmployeeID] = #t.[EmployeeID]\r\n";
			sql += ";select @@rowcount";
			cmd.CommandText = sql;
			dc.Connection.Open();
			var startTime = DateTime.Now;
			object p = cmd.ExecuteScalar();
			var endTime = DateTime.Now;
			optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
			dc.Connection.Close();
			return (int)p;
		}

		#endregion

		#region UpdateData

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, int>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, int newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, int>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, int?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, int? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, int?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, Single>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, Single newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, Single>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, Single?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, Single? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, Single?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, decimal>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, decimal newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, decimal>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, decimal?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, decimal? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, decimal?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, double>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, double newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, double>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, double?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, double? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, double?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, short>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, short newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, short>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, short?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, short? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, short?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, string>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, string newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, string>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, DateTime>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, DateTime newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, DateTime>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, DateTime?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, DateTime? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, DateTime?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, bool newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, bool>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, bool? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, bool?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, Guid>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, Guid newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, Guid>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, Guid?>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, Guid? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, Guid?>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, byte[]>> select, Expression<Func<Acme.Northwind.EFDAL.EmployeeQuery, bool>> where, byte[] newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Employee, Acme.Northwind.EFDAL.EmployeeQuery, byte[]>.UpdateData(select, where, newValue, "Employees", GetDatabaseFieldName, true);
		}

		#endregion

		#region GetDatabaseFieldName

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(Employee.FieldNameConstants field)
		{
			return GetDatabaseFieldName(field.ToString());
		}

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(string field)
		{
			switch (field)
			{
				case "Address": return "Address";
				case "BirthDate": return "BirthDate";
				case "City": return "City";
				case "Country": return "Country";
				case "EmployeeID": return "EmployeeID";
				case "Extension": return "Extension";
				case "FirstName": return "FirstName";
				case "HireDate": return "HireDate";
				case "HomePhone": return "HomePhone";
				case "LastName": return "LastName";
				case "Notes": return "Notes";
				case "Photo": return "Photo";
				case "PhotoPath": return "PhotoPath";
				case "PostalCode": return "PostalCode";
				case "Region": return "Region";
				case "ReportsTo": return "ReportsTo";
				case "Title": return "Title";
				case "TitleOfCourtesy": return "TitleOfCourtesy";
				case "CreatedBy": return "CreatedBy";
				case "CreatedDate": return "CreatedDate";
				case "ModifiedBy": return "ModifiedBy";
				case "ModifiedDate": return "ModifiedDate";
				case "Timestamp": return "Timestamp";
			}
			return string.Empty;
		}

		#endregion

		#region Context

		NorthwindEntities IEntityWithContext.Context
		{
			get { return _internalContext; }
			set { _internalContext = value; }
		}
		private NorthwindEntities _internalContext = null;

		#endregion

		#region Auditing
		string nHydrate.EFCore.DataAccess.IAuditable.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsCreateAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsModifyAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsTimestampAuditImplemented
		{
			get { return true; }
		}

		string nHydrate.EFCore.DataAccess.IAuditable.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		byte[] nHydrate.EFCore.DataAccess.IAuditable.TimeStamp
		{
			get { return this.Timestamp; }
		}

		internal virtual void ResetModifiedBy(string modifier)
		{
			if (this.ModifiedBy != modifier)
				this.ModifiedBy = modifier;
		}

		internal virtual void ResetCreatedBy(string modifier)
		{
			if (this.CreatedBy != modifier)
				this.CreatedBy = modifier;
			this.ResetModifiedBy(modifier);
		}
		#endregion

		#region Static Methods

		/// <summary>
		/// Select a single element by its primary key value
		/// </summary>
		public static Acme.Northwind.EFDAL.Entity.Employee SelectByPK(int employeeID)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Employee.FirstOrDefault(x => x.EmployeeID == employeeID);
			}
		}

		/// <summary>
		/// Returns a list of distinct values based on a predicate
		/// </summary>
		public static IEnumerable<T> GetDistinct<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, T>> select, System.Linq.Expressions.Expression<Func<Employee, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Employee.Where(predicate).Select(select).Distinct().ToList();
			}
		}

		/// <summary>
		/// Returns a count of items based on a predicate
		/// </summary>
		public static int GetCount(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Employee.Count(predicate);
			}
		}

		/// <summary>
		/// Returns a maximum property value of based on a predicate
		/// </summary>
		public static T GetMax<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Employee.Where(predicate).Select(select).Max();
			}
		}

		/// <summary>
		/// Returns a minimum property value of based on a predicate
		/// </summary>
		public static T GetMin<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Employee, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Employee.Where(predicate).Select(select).Min();
			}
		}

		/// <summary>
		/// Creates and returns a metadata object for an entity type
		/// </summary>
		/// <returns>A metadata object for the entity types in this assembly</returns>
		public static Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.EmployeeMetadata GetMetadata()
		{
			var a = typeof(Employee).GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.MetadataTypeAttribute), true).FirstOrDefault();
			if (a == null) return null;
			var t = ((System.ComponentModel.DataAnnotations.MetadataTypeAttribute)a).MetadataClassType;
			if (t == null) return null;
			return Activator.CreateInstance(t) as nHydrate.EFCore.DataAccess.IMetadata as Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.EmployeeMetadata;
		}

		#endregion

		#region Equals
		bool System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee>.Equals(Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee other)
		{
			return this.IsEquivalent(other);
		}
		#endregion

		#region IDataErrorInfo
		/// <summary>
		/// 
		/// </summary>
		string System.ComponentModel.IDataErrorInfo.Error
		{
			get { return this.GetObjectDataErrorInfo(); }
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="columnName"></param>
		/// <returns></returns>
		string System.ComponentModel.IDataErrorInfo.this[string columnName]
		{
			get
			{
				if (string.IsNullOrEmpty(columnName))
					return string.Empty;

				var retval = GetObjectPropertyDataErrorInfo(columnName);
				if (string.IsNullOrEmpty(retval))
				{
					switch (columnName.ToLower())
					{
						case "firstname":
							if (string.IsNullOrEmpty(this.FirstName) || string.IsNullOrEmpty(this.FirstName.Trim()))
								retval = "FirstName is required!";
							break;
						case "lastname":
							if (string.IsNullOrEmpty(this.LastName) || string.IsNullOrEmpty(this.LastName.Trim()))
								retval = "LastName is required!";
							break;
						default:
							break;
					}
				}
				return retval;
			}
		}
		#endregion

	}

	partial class Employee : nHydrate.EFCore.DataAccess.ICreatedAudit, nHydrate.EFCore.DataAccess.IModifiedAudit, nHydrate.EFCore.DataAccess.IConcurrencyAudit
	{
		#region ICreatedAudit Members

		string ICreatedAudit.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		DateTime? ICreatedAudit.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		#endregion

		#region IModifiedAudit Members

		string IModifiedAudit.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		DateTime? IModifiedAudit.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		#endregion

		#region IConcurrencyAudit Members

		byte[] IConcurrencyAudit.TimeStamp
		{
			get { return this.Timestamp; }
		}

		#endregion

	}

}

